package MainPage;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * NewJFrame.java
 *
 * Created on 21-Oct-2010, 22:10:41
 */

/**
 *
 * @author Jacky Ng
 */
public class enterEvent extends javax.swing.JFrame implements ActionListener{

    /** Creates new form NewJFrame */
	Toolkit tk;
	String SQL;
	static String name,event_description,eventType;
	popUpCalendar popUpDate;
	ActionListener comboListener;
	Image background;
	Dimension screensize;
	
	
    public enterEvent() {
    	loadImage2();
        initComponents();
        tk= Toolkit.getDefaultToolkit();
  	    screensize = tk. getScreenSize ();
  	    this.setSize(screensize.width,screensize.height);

    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        mainPanel = new javax.swing.JPanel()
        {
        	public void paintComponent(Graphics g) 
            {
               super.paintComponent(g);
               g.drawImage(background,0,0,screensize.width, screensize.height,this);
            }
        };
        confirm = new javax.swing.JButton();
        cancel = new javax.swing.JButton();
        description = new javax.swing.JLabel();
        dateButton = new date();
        date = new javax.swing.JLabel();
        eventNameText = new javax.swing.JTextField();
        typeChoice = new javax.swing.JComboBox();
        eventName = new javax.swing.JLabel();
        type = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        descriptionText = new javax.swing.JTextArea();
        imageChanger = new javax.swing.JLabel();
        chooseTimehour=new JComboBox();
        chooseTimeminute=new JComboBox();
        time=new JLabel();
        symbol=new JLabel();
        jbtnhome=new JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(null);

        mainPanel.setLayout(null);

        confirm.setText("OK");
        confirm.addActionListener(this);
        mainPanel.add(confirm);
        confirm.setBounds(670, 480, 120, 30);

        cancel.setText("Cancel");
        mainPanel.add(cancel);
        cancel.setBounds(820, 480, 120, 30);
        cancel.addActionListener(this);

        description.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        description.setText("Description :");
        mainPanel.add(description);
        description.setBounds(50, 270, 150, 40);
        mainPanel.add(dateButton);
        dateButton.setBounds(200, 170, 170, 30);

        time.setFont(new java.awt.Font("Tahoma", 0, 18));
        time.setText("              Time:");
        mainPanel.add(time);
        time.setBounds(28, 220, 150, 40);
        
        symbol.setFont(new java.awt.Font("Tahoma", 0, 18));
        symbol.setText(":");
        mainPanel.add(symbol);
        symbol.setBounds(279,227,10,20);
        
        date.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        date.setText("              Date :");
        mainPanel.add(date);
        date.setBounds(28, 170, 150, 30);
        mainPanel.add(eventNameText);
        eventNameText.setBounds(200, 110, 350, 30);

        typeChoice.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        typeChoice.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Birthday", "Sport", "Meeting", "Travelling", "Party", "Other" }));
        typeChoice.addActionListener(comboListener=new ActionListener(){

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				JComboBox cb = (JComboBox)e.getSource();
				eventType = (String)cb.getSelectedItem();
				updateLabel(eventType);
			}});
        mainPanel.add(typeChoice);
        typeChoice.setBounds(750, 370, 190, 50);
        
        chooseTimehour.setFont(new java.awt.Font("Tahoma", 0, 13));
        chooseTimehour.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "00", "01", "02", "03", "04", "05","06", "07", "08", "09", "10", "11"
        		                , "12", "13", "14", "15","16", "17", "18", "19", "20", "21", "22", "23"}));
        mainPanel.add(chooseTimehour);
        chooseTimehour.setBounds(200, 230, 76, 20);
        
        chooseTimeminute.setFont(new java.awt.Font("Tahoma", 0, 13));
        chooseTimeminute.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "00", "01", "02", "03", "04", "05","06", "07", "08", "09", "10", "11"
                , "12", "13", "14", "15","16", "17", "18", "19", "20", "21", "22", "23", "24","25","26","27","28","29","30"
                ,"31", "32", "33", "34", "35","36", "37", "38", "39", "40", "41"
                , "42", "43", "44", "45","46", "47", "48", "49", "50", "51", "52", "53", "54","55","56","57","58","59"}));
        mainPanel.add(chooseTimeminute);
        chooseTimeminute.setBounds(290, 230, 76, 20);
        
        jbtnhome.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resource/home-button.jpg"))); // NOI18N
        jbtnhome.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        mainPanel.add(jbtnhome).setBounds(20, 20, 50, 50);
        
        jbtnhome.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            	firstPage.playAudio2(getClass().getResource("/resource/buttonHit.wav").getFile());
                homeButtonActionPerformed(evt);
            }
        });
        
        eventName.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        eventName.setText("   Event Name :");
        mainPanel.add(eventName);
        eventName.setBounds(30, 110, 150, 30);

        type.setFont(new java.awt.Font("Tahoma", 0, 20)); // NOI18N
        type.setText("   Type :");
        mainPanel.add(type);
        type.setBounds(640, 370, 80, 50);

        descriptionText.setColumns(20);
        descriptionText.setRows(5);
        jScrollPane1.setViewportView(descriptionText);

        mainPanel.add(jScrollPane1);
        jScrollPane1.setBounds(205, 280, 340, 240);

        imageChanger.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resource/Birthday.jpg"))); 
        mainPanel.add(imageChanger);
        imageChanger.setBounds(690, 70, 420, 300);

      
        getContentPane().add(mainPanel);
        mainPanel.setBounds(0, 0, 1300, 750);

        pack();
    }// </editor-fold>

    private void homeButtonActionPerformed(java.awt.event.ActionEvent evt) {
        performFirstPage();
     } 
    
    public void loadImage2()
    {
		ImageIcon Background=new ImageIcon(getClass().getResource("/resource/panel2.jpg"));  
		background=Background.getImage();
    }

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new enterEvent().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify
    private javax.swing.JButton cancel;
    private javax.swing.JButton confirm;
    public static date dateButton;
    private JButton jbtnhome;
    private javax.swing.JLabel date;
    private javax.swing.JLabel time;
    private javax.swing.JLabel description;
    private javax.swing.JTextArea descriptionText;
    private javax.swing.JLabel eventName;
    private javax.swing.JTextField eventNameText;
    private javax.swing.JLabel imageChanger;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JLabel type;
    private javax.swing.JLabel symbol;
    private javax.swing.JComboBox typeChoice;
    private javax.swing.JComboBox chooseTimehour;
    private javax.swing.JComboBox chooseTimeminute;
    // End of variables declaration

	@Override
	public void actionPerformed(ActionEvent evt) {
		// TODO Auto-generated method stub
		
	    
		String command = evt.getActionCommand();
	    
		if (command.equals("OK"))
		{	
			if (dateButton.getText()=="Click date")
			{
				JOptionPane.showMessageDialog(this,"Please select date!","Error Message",
		                JOptionPane.ERROR_MESSAGE);
			}
			else
			{
			firstPage.playAudio2(getClass().getResource("/resource/buttonHit.wav").getFile());
			name=eventNameText.getText();
			String insertDate= dateButton.getText().toUpperCase();
			String insertType=(String) typeChoice.getSelectedItem();
			String inserttime=(String) chooseTimehour.getSelectedItem()+(String) chooseTimeminute.getSelectedItem();
			event_description=descriptionText.getText();
			SQL="INSERT INTO EVENT(USER_CODE,EVENT_TITLE,EVENT_DATE,EVENT_DES,EVENT_TYPE,EVENT_TIME) VALUES ("+userMainPage.userCode+",'"+name+"','"+insertDate.toUpperCase()+"','"+event_description+"','"+insertType+"','"+inserttime+"')";
						
		  try {
		    	userMainPage.stmt.executeQuery(SQL);
		       }
		  catch (SQLException e) 
		  {
			// TODO Auto-generated catch block
		    	e.printStackTrace();
		  }
		  JOptionPane.showMessageDialog(null, "Congratulations! You have been entered a new event!");
	      performFirstPage();
		}}
		if (command.equals("Cancel"))
		{
			firstPage.playAudio2(getClass().getResource("/resource/buttonHit.wav").getFile());
			eventNameText.setText("");
			descriptionText.setText("");
		}

     }
	void performFirstPage()
	{
		//pane.removeAll();
		firstPage first_page=new firstPage()
		{
			public String getParameter(String name)
			{
		           if (name.equalsIgnoreCase("msg"))
		           {
		              return "Local Frame";
		           }
		           return null;
		    }
		};
		first_page.setSize(userMainPage.screensize.width,userMainPage.screensize.height);
		this.dispose();
		first_page.setVisible(true);
		
	}
	protected void updateLabel(String pictureName) 
	{
		imageChanger.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resource/"+pictureName+".jpg")));
    }

}
